package com.siae.controller;


import com.siae.pojo.MessageTemplate;
import com.siae.pojo.vo.Result;
import com.siae.service.MessageTemplateService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/mTemplate")
@Tag(name = "MessageTemplateController",description = "消息操作")
public class MessageTemplateController {
    @Autowired
    private MessageTemplateService templateService;
    @GetMapping
    public Result<List<MessageTemplate>> getAllMTemplates(
            @RequestParam (value = "text",defaultValue = "")String text,
            @RequestParam (value = "type",defaultValue = "")String type){
        return templateService.getAllMTemplates(text,type);
    }
    @GetMapping("/{id}")
    public Result<MessageTemplate> getMTemplateById(@PathVariable("id") Integer id){
        return templateService.getMTemplateById(id);
    }
    @GetMapping("/name/{name}")
    public Result<MessageTemplate> getMTemplateByName(@PathVariable("name") String name){
        return templateService.getMTemplateByName(name);
    }
    @PostMapping
    public Result addMTemplate(@RequestBody MessageTemplate template){
        return templateService.addMTemplate(template);
    }
    @PutMapping
    public Result updateMTemplate(@RequestBody MessageTemplate template){
        return templateService.updateMTemplate(template);
    }
    @DeleteMapping("/{id}")
    public Result deleteMTemplate(@PathVariable("id") Integer id){
        return templateService.deleteMTemplate(id);
    }
}
